package com.zyq.config;

import com.zyq.interceptor.InsertUpdateTimeInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;

@Slf4j
@Configuration
@MapperScan("com.zyq.mapper")
public class MyBatisConfiguration {

    public MyBatisConfiguration(){
        log.debug("创建配置类对象：MybatisConfiguration");
    }

    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @PostConstruct//让本方法在构造方法执行之后执行
    public void addInterceptor(){
        InsertUpdateTimeInterceptor interceptor=new InsertUpdateTimeInterceptor();
        for(SqlSessionFactory sqlSessionFactory:sqlSessionFactoryList){
            sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
        }
    }

}
